package config

import (
	"fmt"
	"github.com/spf13/viper"
)

var RedisConfig *redisConfig

type redisConfig struct {
	Host         string `mapstructure:"host"`
	Password     string `mapstructure:"password"`
	Port         int    `mapstructure:"port"`
	DB           int    `mapstructure:"db"`
	PoolSize     int    `mapstructure:"pool_size"`
	MinIdleConns int    `mapstructure:"min_idle_conns"`
}

func init() {
	RedisConfig = new(redisConfig)
	// 将读取的配置信息保存至全局变量Conf
	if err := viper.Sub("redis").Unmarshal(RedisConfig); err != nil {
		panic(fmt.Errorf("unmarshal redis conf failed, err:%s \n", err))
	}
}
